package com.example.dao.impl;

import com.example.Pojo.HairMaster;
import com.example.Pojo.Profit;
import com.example.dao.AdminManager;

import java.util.List;

public class AdminManagerImpl extends BaseDao implements AdminManager {
    @Override
    public int UpdateInfo(HairMaster hm) {
        String sql = "update hairmaster set username=?,telephone=?,sex=?,level=? where id=?";
        return update(sql,hm.getUsername(),hm.getTelephone(),hm.getSex(),hm.getLevel(),hm.getId());
    }

    @Override
    public int DeleteInfo(int id) {
        String sql = "delete from hairmaster where id=?";
        return update(sql,id);
    }

    @Override
    public int insertInfo(HairMaster hm) {
        String sql = "insert into hairmaster(username,telephone,sex,level)values(?,?,?,?)";
        return update(sql,hm.getUsername(),hm.getTelephone(),hm.getSex(),hm.getLevel());
    }

    @Override
    public List<HairMaster> findAll() {
        String sql = "select * from hairmaster";
        return queryForList(HairMaster.class,sql);
    }

    @Override
    public int findPrice(String type) {
        String sql = "select "+type+" from price" ;
        Number number = (Number)queryCounts(sql);
        return number.intValue();
    }

    @Override
    public int insertProfit(Profit profit) {
        String sql = "insert into profit(username,level,price,date)values(?,?,?,?)";
        return update(sql,profit.getUsername(),profit.getLevel(),profit.getPrice(),profit.getDate());
    }

    @Override
    public int updateProfit(Profit profit,String name) {
        String sql = "update profit set level=?,price=?,date=? where username=?";
        return update(sql,profit.getLevel(),profit.getPrice(),profit.getDate(),profit.getUsername());
    }

    @Override
    public List<Profit> selectProfit() {
        String sql = "select * from profit";
        return queryForList(Profit.class,sql);
    }

    @Override
    public Profit selectProfitByName(String name) {
        String sql = "select * from profit where username=?";
        return queryForOne(Profit.class,sql,name);
    }
}
